package com.example.myapplication;



import static android.opengl.ETC1.getHeight;
import static android.opengl.ETC1.getWidth;

import android.graphics.Matrix;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.mylibrary.MyBall;
import com.example.mylibrary.utils.DisplayUtil;

public class BallActivity extends AppCompatActivity {
    String Mode;
    double currentScale, scale = 1.0, oldDistance;

    MyBall imageView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_ball);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        imageView = findViewById(R.id.myBall);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_POINTER_DOWN:
                oldDistance = DisplayUtil.getDistance(event);
                Mode = "scale";
                break;
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_POINTER_UP:
                Mode = "none";
                currentScale = scale;
                break;
            case MotionEvent.ACTION_MOVE:
                if ("scale".equals(Mode)) {
                    double newDistance = DisplayUtil.getDistance(event);
                    scale = currentScale * newDistance / oldDistance;
                    imageView.setScaleX((float) scale);
                    imageView.setScaleY((float) scale);
                }
                break;
        }
        return true;
    }
}

